<html>
<head><title>Admin Page</title>
<link rel="stylesheet" type="text/css" href="css/Default.css" />
<Script language="javascript" src="data/password.js"></script>
<Script language="javascript" src="exec/login.js"></script>
<noscript>
location.href="noscript.html";
</noscript>
<SCRIPT LANGUAGE="JavaScript">

	window.onload = redir(password.length);
	
//name of cookie: 'eomdmf'
</SCRIPT>

<!-- Add their ip and date to file -->
<?php 
$date = time()/60;
$ip=$_SERVER['REMOTE_ADDR']; //Gets the IP address of the user

//Opens login.txt and fills an array of tempArray[]
$fh = fopen("data/login.txt", "r");
$i=0;
	while(!feof($fh))
	{
		$temp=trim(fgets($fh));
		if(strlen($temp > 7))
		{
			$tempArray[$i]= $temp;
			$i++;
		}
		//echo $tempArray[$i]."<br>";
	}
fclose($fh);

$added = false;

for($i = 0; $i < sizeof($tempArray); $i++)
{
	if($ip == substr($tempArray[$i], 0, strpos($tempArray[$i], '-'))) //Checks if the IP address has already been added to the list
	{
		$added = true;
		$tempArray[$i] = $ip."-".$date;
		break;
	}
}

if(!$added) //Adds the IP address if it hasn't already been added
{
	$tempArray[sizeof($tempArray)] = $ip."-".$date;
}

//Sorts IP addresses based on date of login.
for($i = 0; $i < sizeof($tempArray); $i++)
{
	for($j = sizeof($tempArray)-1; $j > 0; $j--)
	{
		if(substr($tempArray[$j], strpos($tempArray[$j], '-')) <= substr($tempArray[$j-1], strpos($tempArray[$j-1], '-'))) //Compares IP date values
		{
			$temp = $tempArray[$j-1];
			$tempArray[$j-1] = $tempArray[$j];
			$tempArray[$j] = $temp;
		}
	}
}

$i=1;
$var = 11;
if(sizeof($tempArray) < 11) //Limits the array to the last 11 addresses
{
	$i = 0;
	$var = sizeof($tempArray);
}

$fh = fopen("data/login.txt", "w+");

if($fh==false)
	die("unable to create file");
	
while($i < $var) //Writes the new array of IP addresses to the login.txt file
{
	if(strlen($tempArray[$i]) > 7)
	{
		fwrite($fh,$tempArray[$i]."\n");
	}
	$i++;
}

fclose($fh);
?>

</HEAD>
<body >
<fieldset style="border-color:bfae20">
	<br>

	<font size="3.5" face="Arial">
	<b>
	Digital Media Feed
	</b>
	</font>
<center>
<table border="0">
<tr>
<td>
<center>
	<FORM METHOD="LINK" ACTION="index.html">
	<INPUT TYPE="submit" VALUE="Home Page">
	</FORM>
	
<!-- non-root/admin -->
<div id="basic">
	<FORM METHOD="LINK" ACTION="Add_P_Announcements.php">
	<INPUT TYPE="submit" VALUE="Add Announcement"><!-- one at a time -->
	</FORM>
	
	<FORM METHOD="LINK" ACTION="Add_P_NewsFeed.php">
	<INPUT TYPE="submit" VALUE="Add Item To News Feed"><!-- one at a time -->
	</FORM>
</div>
	
<!-- admin + root -->
<div id="admin">
	<FORM METHOD="LINK" ACTION="Show_Announcements.php">
	<INPUT TYPE="submit" VALUE="View/Change Announcements">
	</FORM>

	<FORM METHOD="LINK" ACTION="Add_NewsFeed.php">
	<INPUT TYPE="submit" VALUE="Add Item To News Feed">
	</FORM>

	<FORM METHOD="LINK" ACTION="Show_NewsFeed.php">
	<INPUT TYPE="submit" VALUE="View/Change News Feed">
	</FORM>
</div>
<!-- root -->
<div id="root">
	<FORM METHOD="LINK" ACTION="Show_Media.php">
	<INPUT TYPE="submit" VALUE="View/Change Media Playlist">
	</FORM>
	
	<FORM METHOD="LINK" ACTION="Show_P_NewsFeed.php">
	<INPUT TYPE="submit" VALUE="Approve/Deny Pending News">
	</FORM>
	
	<FORM METHOD="LINK" ACTION="Show_P_Announcements.php">
	<INPUT TYPE="submit" VALUE="Approve/Deny Pending Announcements">
	</FORM>
	
	<FORM METHOD="LINK" ACTION="PanicMenu.html">
	<INPUT TYPE="submit" VALUE="Panic Menu">
	</FORM>

	<FORM METHOD="LINK" ACTION="Reset.php">
	<INPUT TYPE="submit" VALUE="Reset">
	</FORM>		

</div>

<script language="javascript">
	var cookie = GetCookie('eomdmf');
	if( authLevel(cookie) < 2){
		document.getElementById("basic").innerHTML = "";
	}
	if( authLevel(cookie) > 1){
		document.getElementById("admin").innerHTML = "";
		document.getElementById("root").innerHTML = "";
	}else if( authLevel(cookie) > 0){
		document.getElementById("root").innerHTML = "";
	}
</script>

	<FORM METHOD="LINK" ACTION="Admin_Notes.html">
	<INPUT TYPE="submit" VALUE="Help Files">
	</FORM>
	
	<FORM METHOD="LINK" onclick="DeleteCookie('eomdmf');redir();">
	<INPUT TYPE="submit" VALUE="Log Out">
	</FORM>
</center>	
</td>
</tr>
</table>
</center>

</fieldset>
Last Logins: <br>
<?php
for($i = 0; $i < sizeof($tempArray); $i++)
{
	echo substr($tempArray[$i], 0, strpos($tempArray[$i], '-'))."<br>"; //Displays the array of the last logins.
}
?>

<center>
<img src= "media/Gold_Lion.jpg"/>
</center>

<div align="right">
	<FORM METHOD="LINK" ACTION="Thanks.html">
	<INPUT TYPE="submit" VALUE="Credits">
	</FORM>
</div>
</body>
</html>
